package com.leff.cards.request;

import java.util.ArrayList;

import com.leff.cards.Dictionary;
import com.leff.cards.StoreWrapper;
import com.leff.cards.entity.Group;

public class GetGroups extends Request {

	public GetGroups(Dictionary dict) {
		super(dict);
	}
	
	public RequestResult doGetGroups() {
		
		RequestResult result = this.verifyRequiredParameters(Parameter.ID);
		if(!result.isSuccessful()) {
			return result;
		}
		
		Long id = Long.parseLong(mDictionary.get(Parameter.ID).toString());
		ArrayList<Group> groups = StoreWrapper.getGroupsForUser(id);
		
		ArrayList<Object> json = new ArrayList<Object>();
		for(Group G : groups) {
			json.add(G.toJSONForUserId(id));
		}
		
		result.res = Dictionary.withObject("groups", json);
		
		return result;
	}
}
